package site.thatime.hyts.config;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.StringTypeHandler;

/**
 * 去除数据库中列类型为char的后面的空格
 * 
 * @author zw-zheng
 *
 */
@MappedJdbcTypes({ JdbcType.CHAR })
public class JdbcCharTypeHandler extends StringTypeHandler {

	String trim(String value) {
		return value == null ? null : value.trim();
	}

	@Override
	public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
		return trim(super.getNullableResult(rs, columnName));
	}

	@Override
	public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		return trim(super.getNullableResult(rs, columnIndex));
	}

	@Override
	public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
		return trim(super.getNullableResult(cs, columnIndex));
	}

}
